package com.bwie.parkdemo.mvvm.model.entity;

import com.bwie.lib_core.base.BaseEntity;
import com.google.gson.Gson;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 车辆颜色实体类
 * {"msg":"查询成功","values":"[{\"colorId\":47,\"colorValue\":\"#F8F8FF\"},
 * {\"colorId\":48,\"colorValue\":\"#8B0000\"},
 * {\"colorId\":49,\"colorValue\":\"#000000\"},
 * {\"colorId\":50,\"colorValue\":\"#5be62d\"},
 * {\"colorId\":51,\"colorValue\":\"#e6e52d\"},{\"colorId\":52,\"colorValue\":\"#2d7ae6\"}]","statuesCode":"200"}
 * */
public class CarColorEntity extends BaseEntity {
    private String values;
    private ArrayList<Object>colores;

    public ArrayList<Object> getColores() {
        if (colores == null)
            colores = new ArrayList<>();
        if (values!=null){
            try {
                JSONArray jsonArray = new JSONArray(values);
                for (int i = 0;i < jsonArray.length();i ++){
                    JSONObject job = jsonArray.getJSONObject(i);
                    Values values = new Gson().fromJson(job.toString(),Values.class);
                    colores.add(values);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }

        }
        return colores;
    }

    public static class Values{
        public int colorId;
        public String colorValue;
    }
}
